<%@include file="/pub/import.jsp"%>
<%@include file="/pub/header.jsp"%>
<%
	int projectID = RequestUtil.getIntParameter(request,"projectId",0);
	Project project = ProjectHandler.getProject(projectID);
	int treeId = RequestUtil.getIntParameter(request,"treeId",0);
	
	List<User> userList = new ArrayList<User>();
    
    int[] pidarr = new int[]{0,0,0,0};
    if(!StringUtils.isEmpty(project.getBuildUnit())) pidarr[0] = 1;
    if(!StringUtils.isEmpty(project.getConstructUnit())) pidarr[1] = 3;
    if(!StringUtils.isEmpty(project.getSupervisorUnit())) pidarr[2] = 40;    
    if(!StringUtils.isEmpty(project.getDesignUnit())) pidarr[3] = 44;
    List<ScoreTree> treeList = ScoreTreeHandler.loadByPIDs(pidarr);
    
    String users = project.getScoreUser();
    if(!StringUtils.isEmpty(users)) {
      String[] userArr = users.split(",");
      for(String userId : userArr) {
        userList.add(UserHandler.getUser(Integer.parseInt(userId)));
      }
    }

    float totalScore = 0.0f;
    if(!StringUtils.isEmpty(project.getBuildUnit())) totalScore+=100;
    if(!StringUtils.isEmpty(project.getConstructUnit())) totalScore+=100;
    if(!StringUtils.isEmpty(project.getSupervisorUnit())) totalScore+=100;
    if(!StringUtils.isEmpty(project.getDesignUnit())) totalScore+=100;    
    
    double result = 0.0d;
	result = ProjectItemsHandler.getProjectIdScoreSum(projectID);
	BigDecimal b = new BigDecimal(result);
	double currentScore = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    
    ScoreTree tree = ScoreTreeHandler.loadById(treeId);//延时加载评分子项,先加载树
   
     List<ProjectItems> resultProjectItems= ProjectItemsHandler.getByProjectIdTreeId(projectID,treeId);
    
    List<ProjectItems> allProjectItems = ProjectItemsHandler.getByProject(projectID);
    Map<Integer, String> allProjectItemMap = new HashMap<Integer,String>();
    for(ProjectItems p: allProjectItems) {
      allProjectItemMap.put(p.getScoreItem().getScoreTree().getId(), "true");
    }
    context.put("allProjectItemMap", allProjectItemMap);    
    
    context.put("totalScore", totalScore);
    context.put("currentScore", currentScore);
    context.put("treeList", treeList);
    context.put("userList", userList); 
    context.put("project",project);
    context.put("DateUtil", new DateUtil());
    context.put("projectID",projectID);
    context.put("scoreTree",tree);
    context.put("projectItemsList",resultProjectItems);
	out.println(TemplateUtil.getOutput(context,"/view/project/newProjectView.html"));
 %>
<%@include file="/pub/footer.jsp"%>